﻿//-----------------------------------------------------------------------
// <copyright>
//     Copyright (c) Artur Mustafin. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Reflection;
using Excel.Expressions.Interfaces;

namespace Excel.Expressions.Classes
{
    internal class External
    {
        private static External _instance;

        static External()
        {
            _instance = new External();
        }

        private CompositionContainer _container;
        private AssemblyCatalog _catalog;

        private External()
        {
            _catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
            _container = new CompositionContainer(_catalog);
            _container.ComposeParts(this);
        }

        [ImportMany(AllowRecomposition = true)]
        private IEnumerable<IBinaryFunction> InternalFunctions { get; set; }

        [ImportMany(AllowRecomposition = true)]
        private IEnumerable<IEnumerableFunction> InternalEnumerableFunctions { get; set; }

        [ImportMany(AllowRecomposition = true)]
        private IEnumerable<IEnumerableExpressionFunction> InternalEnumerableExpressionFunctions { get; set; }

        public static IEnumerable<IBinaryFunction> BinaryFunctions { get { return _instance.InternalFunctions; } }

        public static IEnumerable<IEnumerableFunction> EnumerableFunctions { get { return _instance.InternalEnumerableFunctions; } }

        public static IEnumerable<IEnumerableExpressionFunction> EnumerableExpressionFunctions { get { return _instance.InternalEnumerableExpressionFunctions; } }
    }
}
